#include "exportToolbar.h"
#include "exportDialog.h"
#include "MaxIcon.h"
ClassDesc* GetWorldExportDesc() {return &WorldExportDesc;}
int exportToolBarProc ::ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam) 
{
	if(message == WM_COMMAND)
	{
		if(LOWORD(wParam) == ID_BUILDDIALOG)
			showExportDialog();
		else if(LOWORD(wParam) == ID_MODELDIALOG)
			showModelDialog();

		return TRUE;
	}
	return false;
}


void CWorldExportToolBar::BeginEditParams(Interface *pIp,IUtil *g_pUp) 
{
	g_pIp = pIp;
	
	ICUIFrame* iFrame = GetICUIFrame();
	if (iFrame) {
		iFrame->Hide(FALSE);
		if (!iFrame->IsFloating())
			GetCUIFrameMgr()->RecalcLayout(TRUE);
		return;
	}

	HWND hParent = g_pIp->GetMAXHWnd();
	HWND hWnd = CreateCUIFrameWindow(hParent, _T("worldExport"), 0, 0, 250, 100);

	iFrame = ::GetICUIFrame(hWnd);
	iFrame->SetContentType(CUI_TOOLBAR);
	iFrame->SetPosType( CUI_VERT_DOCK );

	HWND hToolbar = CreateWindow(CUSTTOOLBARWINDOWCLASS,NULL,WS_CHILD | WS_VISIBLE,
								0, 0, 250, 100,hWnd,NULL,hInstance,NULL);
	hToolbarWnd = hToolbar;

	ICustToolbar *iToolBar = GetICustToolbar(hToolbar);
	iToolBar->LinkToCUIFrame(hWnd, NULL);

	tbMsgHandler = new exportToolBarProc();
	iFrame->InstallMsgHandler(tbMsgHandler);

	iToolBar->AddTool(TBITEM(CTB_PUSHBUTTON, new MaxBmpFileIcon(_T("CUITest"), 0+2), ID_BUILDDIALOG));
	iToolBar->AddTool(TBITEM(CTB_PUSHBUTTON, new MaxBmpFileIcon(_T("CUITest"), 0+3), ID_MODELDIALOG));

	GetCUIFrameMgr()->DockCUIWindow(GetParent(iFrame->GetContentHandle()), CUI_LEFT_DOCK, NULL);
	GetCUIFrameMgr()->RecalcLayout(TRUE);

	ReleaseICustToolbar(iToolBar);
	iToolBar = NULL;
}


void CWorldExportToolBar::EndEditParams(Interface *pIp,IUtil *g_pIp) {

	g_pIp = NULL;

	// Hide the toolbar so the user can't execute anything 
	// when we're not active.
	ICUIFrame* iFrame = GetICUIFrame();
	if (iFrame) {
		iFrame->Hide(TRUE);
		// If the toolbar was docked we need to recalc the layout
		// so the toolbar will be removed.
		if (!iFrame->IsFloating()) {
			GetCUIFrameMgr()->RecalcLayout(TRUE);
		}
	}
	ReleaseICUIFrame(iFrame);
}


ICUIFrame* CWorldExportToolBar::GetICUIFrame()
{
	HWND hFrameWnd = GetParent(hToolbarWnd);
	return  ::GetICUIFrame(hFrameWnd);
}
